package br.com.agenda.entity;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "USUARIO")
public class UsuarioEntity implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer		codUsu;

	private String		nome;
	private String		senha;

	@ManyToMany(targetEntity = TarefaEntity.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name = "USUARIO_TAREFA", joinColumns = @JoinColumn(name = "CODUSU"), inverseJoinColumns = @JoinColumn(name = "CODTAREFA"))
	private Set<TarefaEntity>	tarefas;

	public void addTarefa(TarefaEntity tarefa) {
		if (tarefas == null) {
			tarefas = new HashSet<TarefaEntity>();
		}

		tarefas.add(tarefa);
	}

	public Set<TarefaEntity> getTarefas() {
		return tarefas;
	}

	public Integer getCodUsu() {
		return codUsu;
	}

	public void setCodUsu(Integer codUsu) {
		this.codUsu = codUsu;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}
}
